home *** CD-ROM | disk | FTP | other *** search
- /* © 1991, Bowers Development Corp. */
- /* Dragging.c */
-
- #include <QuickDraw.h>
- #include <ToolUtils.h>
- #include <TextEdit.h>
- #include <Windows.h>
-
- #include "Globals.h"
- #include "ResourceDefs.h"
-
- #include "Dragging.h"
-
- #pragma segment Dragging
-
- /*----------*/
- static short Abs (short x);
- static short Abs (short x)
- {
- return ((x < 0) ? (-x) : (x));
- } /*Abs*/
-
- /*----------*/
- Boolean StartMove (Point *startPt,
- short *constraint)
- {
- #define slop 2
-
- Rect slopRect;
- Point mousePt;
-
- #define sP (*startPt)
- SetRect (&slopRect, sP.h, sP.v, sP.h + 1, sP.v + 1);
- #undef sP
-
- InsetRect (&slopRect, -slop, -slop);
-
- mousePt = *startPt;
- while (StillDown () && PtInRect (mousePt, &slopRect)) {
- GetMouse (&mousePt);
- }
-
- if (StillDown ()) {
- *constraint = noConstraint;
- if ((curEvent.modifiers & optionKey) != 0) {
- if (Abs (mousePt.h - (*startPt).h)
- > Abs (mousePt.v - (*startPt).v)) {
- *constraint = hAxisOnly;
- } else {
- *constraint = vAxisOnly;
- }
- }
- }
-
- *startPt = mousePt;
- if ((*startPt).h > (slopRect).right) { (*startPt).h = (slopRect).right; }
- if ((*startPt).h < (slopRect).left) { (*startPt).h = (slopRect).left - 1; }
- if ((*startPt).v > (slopRect).bottom) { (*startPt).v = (slopRect).bottom; }
- if ((*startPt).v < (slopRect).top) { (*startPt).v = (slopRect).top - 1; }
-
- return (StillDown ());
- } /*StartMove*/
-
- /*----------*/
- Boolean TrackMove (RgnHandle dragRgn,
- Point startPt,
- Rect bounds,
- short constraint,
- short *deltaH,
- short *deltaV,
- DragGrayRgnProcPtr actionProc)
- {
- #undef slop
- #define slop 20
-
- Rect limitRect;
- Rect slopRect;
- long delta;
- register Rect *dragBBox;
-
- dragBBox = &(**dragRgn).rgnBBox;
- SetRect (&limitRect,
- bounds.left - dragBBox->left,
- bounds.top - dragBBox->top,
- bounds.right - dragBBox->right + 1,
- bounds.bottom - dragBBox->bottom + 1);
-
- OffsetRect (&limitRect, startPt.h, startPt.v);
- slopRect = limitRect;
- InsetRect (&slopRect, -slop, -slop);
-
- delta = DragGrayRgn (dragRgn, startPt, &limitRect,
- &slopRect, constraint, actionProc);
- *deltaV = HiWord (delta);
- *deltaH = LoWord (delta);
-
- if (( delta == 0)
- || (*deltaH == 0x8000)
- || (*deltaV == 0x8000)) {
- return (false);
- } else {
- return (true);
- }
- } /*TrackMove*/
-
- /*----------*/
- Boolean TrackRange (Point anchorPt,
- Rect *range)
- {
- PenState savePen;
- Point curPos;
- Point newPos;
- long lastTicks;
-
- GetPenState (&savePen);
- PenNormal ();
- PenMode (notPatXor);
- #ifdef dangerousPattern
- PenPat (qd.gray);
- #else
- PenPat (&qd.gray);
- #endif
-
- newPos = anchorPt;
- curPos = newPos;
- Pt2Rect (anchorPt, curPos, range);
- FrameRect (range); /*Draw*/
-
- lastTicks = 0;
- while (StillDown ()) {
- if (TickCount () >= lastTicks + 2) {
- GetMouse (&newPos);
- if (!EqualPt (newPos, curPos)) {
- FrameRect (range); /*Undraw*/
- curPos = newPos;
- Pt2Rect (anchorPt, curPos, range);
- FrameRect (range); /*Draw*/
- }
- lastTicks = TickCount ();
- }
- } /*while*/
-
- FrameRect (range); /*Undraw*/
-
- SetPenState (&savePen);
-
- return (!EmptyRect (range));
- } /*TrackRange*/
-
- /*----------*/
- static void PinBotRight (Rect limitRect,
- Rect *sizeRect);
- static void PinBotRight (Rect limitRect,
- Rect *sizeRect)
- {
- #define lR limitRect
- if (sizeRect->bottom < lR.top) sizeRect->bottom = lR.top;
- if (sizeRect->right < lR.left) sizeRect->right = lR.left;
- if (sizeRect->bottom > lR.bottom) sizeRect->bottom = lR.bottom;
- if (sizeRect->right > lR.right) sizeRect->right = lR.right;
- #undef lR
- } /*PinBotRight*/
-
- /*----------*/
- static Boolean InSlop (Rect *sizeRect,
- Rect *slopRect);
- static Boolean InSlop (Rect *sizeRect,
- Rect *slopRect)
- {
- Boolean isIn;
- Point bR;
-
- bR.v = sizeRect->bottom;
- bR.h = sizeRect->right;
- isIn = PtInRect (bR, slopRect);
- return (isIn);
- } /*InSlop*/
-
- /*----------*/
- Boolean TrackRect (Rect *sizeRect,
- Rect limitRect,
- DragProcPtr actionProc)
- {
- PenState savePen;
- Point curPos;
- Point newPos;
- Point offset;
- Point bR;
- Rect slopRect;
- long lastTicks;
- long temp;
-
- GetPenState (&savePen);
- PenNormal ();
- PenMode (notPatXor);
- #ifdef dangerousPattern
- PenPat (qd.gray);
- #else
- PenPat (&qd.gray);
- #endif
-
- slopRect = limitRect;
- InsetRect (&slopRect, -20, -20);
-
- GetMouse (&curPos);
- bR.v = sizeRect->bottom;
- bR.h = sizeRect->right;
- temp = DeltaPoint (bR, curPos);
- offset = *(Point *) &temp;
-
- FrameRect (sizeRect); /*Draw*/
-
- lastTicks = 0;
- while (StillDown ()) {
- if (TickCount () >= lastTicks + 2) {
- GetMouse (&newPos);
- if (!EqualPt (newPos, curPos)) {
- if (InSlop (sizeRect, &slopRect)) {
- FrameRect (sizeRect); /*Undraw*/
- }
- curPos = newPos;
- AddPt (offset, &newPos);
- sizeRect->bottom = newPos.v; /*botRight (sizeRect) = newPos;*/
- sizeRect->right = newPos.h;
- if (InSlop (sizeRect, &slopRect)) {
- PinBotRight (limitRect, sizeRect);
- FrameRect (sizeRect); /*Draw*/
- }
- if (actionProc != NULL) {
- (*actionProc) ();
- }
- }
- lastTicks = TickCount ();
- }
- } /*while*/
-
- if (InSlop (sizeRect, &slopRect)) {
- FrameRect (sizeRect); /*Undraw*/
- }
-
- SetPenState (&savePen);
-
- return (InSlop (sizeRect, &slopRect));
- } /*TrackRect*/
-
- /*----------*/
- static void FrameLine (Rect sizeRect);
- static void FrameLine (Rect sizeRect)
- {
- MoveTo (sizeRect.left, sizeRect.top);
- LineTo (sizeRect.right - 1, sizeRect.bottom - 1);
- } /*FrameLine*/
-
- /*----------*/
- Boolean TrackLine (Rect *sizeRect,
- Rect limitRect,
- DragProcPtr actionProc)
- {
- PenState savePen;
- Point curPos;
- Point newPos;
- Point Offset;
- Point bR;
- Rect slopRect;
- long lastTicks;
- long temp;
-
- GetPenState (&savePen);
- PenNormal ();
- PenMode (notPatXor);
- #ifdef dangerousPattern
- PenPat (qd.gray);
- #else
- PenPat (&qd.gray);
- #endif
-
- slopRect = limitRect;
- InsetRect (&slopRect, -20, -20);
-
- GetMouse (&curPos);
- bR.v = sizeRect->bottom;
- bR.h = sizeRect->right;
- temp = DeltaPoint (bR, curPos);
- Offset = *(Point *) &temp;
-
- FrameLine (*sizeRect); /*Draw*/
-
- lastTicks = 0;
- while (StillDown ()) {
- if (TickCount () >= lastTicks + 2) {
- GetMouse (&newPos);
- if (!EqualPt (newPos, curPos)) {
- if (InSlop (sizeRect, &slopRect)) {
- FrameLine (*sizeRect); /*Undraw*/
- }
- curPos = newPos;
- AddPt (Offset, &newPos);
- sizeRect->bottom = newPos.v; /*botRight (sizeRect) = newPos;*/
- sizeRect->right = newPos.h;
- /* ?? constrain line to be horizontal or vertical ?? */
- /* With sizeRect do { */
- /* if ((right - left) > (bottom - top)) { */
- /* bottom = top + 1; */
- /* } else { */
- /* right = left + 1; */
- /* } */
- /* } */ /*with*/
- if (InSlop (sizeRect, &slopRect)) {
- PinBotRight (limitRect, sizeRect);
- FrameLine (*sizeRect); /*Draw*/
- }
- if (actionProc != NULL) {
- (*actionProc) ();
- }
- }
- lastTicks = TickCount ();
- }
- } /*while*/
-
- if (InSlop (sizeRect, &slopRect)) {
- FrameLine (*sizeRect); /*Undraw*/
- }
-
- SetPenState (&savePen);
-
- return (InSlop (sizeRect, &slopRect));
- } /*TrackLine*/
-